package megrez.oss.minio.web.vo;

import java.util.Date;

import io.minio.StatObjectResponse;
import lombok.Data;
import megrez.oss.minio.utils.UserData;

/**
 * 对象元信息
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Data
public class MetadataVO {
    private String fileName;
    private String createdBy;
    private Date createdDate;
    private Long size;
    private String objectId;
    private String objectName;
    private String bucket;

    public static MetadataVO of(StatObjectResponse stat) {
        UserData userData = UserData.of(stat.userMetadata());
        MetadataVO metadata = new MetadataVO();

        metadata.setCreatedBy(userData.getCreatedBy());
        metadata.setFileName(userData.getFileName());
        metadata.setObjectName(stat.object());
        metadata.setObjectId(userData.getObjectId());
        if (stat.lastModified() != null) {
            metadata.setCreatedDate(Date.from(stat.lastModified().toInstant()));
        }
        metadata.setBucket(stat.bucket());
        return metadata;
    }
}
